package com.yuexunit.finance.project.service;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.common.util.DateUtils;
import com.yuexunit.finance.project.entity.FinanceExpenseDetailEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.StringUtil;

/**
*@version 创建时间：2016年9月28日 下午4:19:18
*@author wenwenlong
*类说明
*/

@Implements(FinanceExpenseDetailService.class)
public class FinanceExpenseDetailServiceImpl implements FinanceExpenseDetailService {

	@Override
	@Transactional
	public Long createFinanceExpenseDetail(FinanceExpenseDetailEntity entity) {
		entity.setCreateDateTime(DateUtils.now());
		PersistUtil.insert(entity);
		return entity.getExpenseDetailId();
	}

	@Override
	@Transactional
	public void updateFinanceExpenseDetail(FinanceExpenseDetailEntity entity) {
		PersistUtil.update(entity);
	}

	@Override
	public FinanceExpenseDetailEntity inquireFinanceExpenseDetail(Long expenseDetailId) {
		return PersistUtil.get(FinanceExpenseDetailEntity.class, expenseDetailId);
	}

	@Override
	public PageList<FinanceExpenseDetailEntity> inqurieFinanceExpenseDetailPageList(Long financeId, String expenseItem, PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceExpenseDetailEntity.class);
		criteria.add(Restrictions.eq("financeId", financeId));
		if (StringUtil.isNotBlank(expenseItem)) {
			criteria.add(Restrictions.eq("expenseItem", expenseItem));
		}
		criteria.addOrder(Order.desc("createDateTime"));
		return PersistUtil.get(criteria, page);
	}
}
